//
//  BaseTableViewController.swift
//  Three-SinaWeibo
//
//  Created by 李旭阳 on 15/11/11.
//  Copyright © 2015年 apple. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController, VisitorLoginViewDelegate {
    
    
    var userLogin = UserAccountViewModel().userLogin
    var visitorLoginView: VisitorLoginView?
    
    //loadVIew是苹果专门为手写代码 准备的  等效与 sb / xib
    //一旦实现这个方法  xib / sb就自动失效
    //会自动检测 view是否为空  如果为空 会自动调用 loadView方法
    override func loadView() {
        userLogin ? super.loadView() : loadVisitorView()
    }
    
    private func loadVisitorView(){
        visitorLoginView = VisitorLoginView()
        //设置代理
        visitorLoginView?.visitorDelegate = self
        view = visitorLoginView
        
        //创建item
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登陆", style: .Plain, target: self, action: "visitorWillLogin")
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "visitorWillRegister")
    }
    //MARK: 实现代理方法
    func visitorWillLogin(){
        print("come on")
        let oauth = OAuthViewController()
        let nav = UINavigationController(rootViewController: oauth)
        presentViewController(nav, animated: true, completion: nil)
    }
    func visitorWillRegister(){
        print("come in")
    }
}
